package appita.general;


import org.json.JSONArray;
import org.json.JSONException;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import appita.parser.Parser;
import appita.util.Effect;

public class ImageAdapterIta extends BaseAdapter {

    private Activity activity;
    private static LayoutInflater inflater=null;
    private final Context context;
	private String [] nomi;
	private String [] foto;
	private String [] audio;
	private JSONArray  arrayParole;

	
    public ImageAdapterIta(Context  context,String [] nomi, String [] foto,String [] audio) {
    	super();
		this.context = context;
		this.nomi=nomi;
		this.foto=foto;
		this.audio=audio;
	
	
    }


    public int getCount() {
        return data.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public static class ViewHolder{
        public TextView text;
        public ImageView image;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
    	
    
     /*   View vi=convertView;
        ViewHolder holder;
        if(convertView==null){
            vi = inflater.inflate(R.layout.image_gallery_items, null);
            holder=new ViewHolder();
            holder.text=(TextView)vi.findViewById(R.id.textView1);
            holder.image=(ImageView)vi.findViewById(R.id.image);
            vi.setTag(holder);
        }
        else
            holder=(ViewHolder)vi.getTag();
        holder.text.setText(name[position]);
        final int stub_id=data[position];
        holder.image.setImageResource(stub_id);
        return vi;*/
    	
  
    	
    	LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.image_gallery_items, parent, false);
		TextView textView = (TextView) rowView.findViewById(R.id.textView1);
		ImageView imageView = (ImageView) rowView.findViewById(R.id.image);
		Button audioButton=(Button) rowView.findViewById(R.id.audio);
		int resource_id=context.getResources().getIdentifier(foto[position], "drawable",context.getApplicationInfo().packageName);
		int resource_audio_id=context.getResources().getIdentifier(audio[position],"raw", context.getApplicationInfo().packageName);
		imageView.setImageResource(resource_id);
		textView.setText(nomi[position]);
		final Effect audioParole=new Effect(context,resource_audio_id);
		
		 audioButton.setOnClickListener(new OnClickListener() {
				public void onClick(View arg0) {
					audioParole.play();
				}
			});
   
    	return rowView;
    	
    }



	
	 private int[] data = {
             R.drawable.a, R.drawable.b,
             R.drawable.c
           
     };


  
}
